<?php
namespace App\Services;

use Cache;

class Msgtpl
{
	// 新单通知用户，给用户反馈
    const TEMP_NEW_USER     = 'QHoUaH3Dvys-FYwNd9TCxs72QXFBzQgzALS624ar0Hs';
    const TEMP_NEW_MANAGER = 'OR1sMjpBSQuoKy3qWfMu-uoE6RCK6awUqZkWOZwH9wk';

   // const TEMP_PROCESS ='ejTcT46pRYwMI3ylDqNHFWtEHh3y6RcKSyArBd0_paY';

    // 报修处理提醒
    const TEMP_NOTICE = 'Atp9VQGTu-ZfunmgNFiGvxbQG2EEeJ6XpvTxfKq7bZo';

    // 工单完成通知
    const TEMP_COMPLETE = 'mukBv1I_8lFmYCXJ1Qb-pTlfjOx90e140Hfe7h5VkD4';
    
    // 维修费用通知
    const TEMP_PRICE    = 'egzBp_ZJ-TkZ4oOpgLUsEenQuqnoQEp4USDJ04LpvMo';

    // 退单模板
    const TEMP_REFUND = 'WIi5QkcPBr6YbW6WygOuS9oGrZo7MjoFBqCIQM71_4U';


    // 物业管理通知
    const NOTICE = 'drU4CoUBFq9a0gIZiJ0ziqoKyugngt9C7ky7oxbNfjs';


 
    /**
     * 收费通知模板
     */
    public static function notice($data)
    {
        $url = '';        
        $app = app('wechat.official_account');
        $users = $app->user->list();
        if($users['total']>1) {
           
            foreach ($users['data']['openid'] as $openid) {
                $app->template_message->send([
                    'touser' => $openid,
                    'template_id' => self::NOTICE,
                    'url' => $url,
                    'data' => [
                       'first'    => $data['first'],
                        'keyword1' => $data['title'],
                        'keyword2' => $data['created_at'],            
                        'keyword3' => $data['contents'],                
                        'remark' => '单击查看详细...',                  
                    ],
                ]);
            }
        }
        
        
    }
    

	/**
	 * 新工单模板  工单提交成功通知
	 */
	public static function tempNewTask($data)
	{
		$app = app('wechat.official_account');
        $app->template_message->send([
            'touser' => $data['openid'],
            'template_id' => self::TEMP_NEW_USER,
            'url' => config('app.url').'/user/task/show/'.$data['task_id'],
            'data' => [
                'first'    => [$data['first'],'#FF0000'],
                'keyword1' => ['value'=>date('Y年m月d日 H:i'),'color'=>'#550038'],
                'keyword2' => $data['code'], 
                'remark' => $data['remark'],                
            ],
        ]);
	}

    /**
     * 新工单模板 发给负责人
     */
    public static function tempNewTaskToManager($data)
    {
        $app = app('wechat.official_account');
        $app->template_message->send([
            'touser' => $data['openid'],
            'template_id' => self::TEMP_NEW_MANAGER,
            'url' => config('app.url').'/user/task/show/'.$data['task_id'],
            'data' => [
                'first'    => [$data['first'],'#FF0000'],
                'keyword1' => [$data['title'],'#00FF00'],
                'keyword2' => $data['customer_name'],
                'keyword3' => '报修',
                'keyword4' => '待处理',
                'keyword5' => $data['village_name'],
                'remark' => $data['remark'],                
            ],
        ]);
    }

    /**
     * 报修处理提醒 发给负责人
     */
    public static function tempNoticeToManager($data)
    {
        $app = app('wechat.official_account');
        $app->template_message->send([
            'touser' => $data['openid'],
            'template_id' => self::TEMP_NOTICE,
            'url' => config('app.url').'/user/task/show/'.$data['task_id'],
            'data' => [
                'first'    => [$data['first'],'#00FF00'],
                'keyword1' => $data['customer_name'],
                'keyword2' => $data['mobile'],
                'keyword3' => $data['remark'],              
                'keyword4' => date('Y-m-d H:i'),
                'remark' => $data['memo'],                
            ],
        ]);
    }
    


    /**
     * 工单进度模板
     */
    public static function tempProcessTaskToManager($data)
    {
        $app = app('wechat.official_account');
        $app->template_message->send([
            'touser' => $data['openid'],
            'template_id' => self::TEMP_PROCESS_MANAGER,
            'url' => config('app.url').'/user/task/show/'.$data['task_id'],
            'data' => [
                'first'    => $data['first'],
                'keyword1' => $data['code'],
                'keyword2' => $data['title'],
                'keyword3' => '新消息',
                'keyword4' => $data['truename'],
                'remark' => $data['remark'],                
            ],
        ]);
    }

    /**
     * 工单完成模板
     */
    public static function tempComplete($data)
    {
        $app = app('wechat.official_account');
        $app->template_message->send([
            'touser' => $data['openid'],
            'template_id' => self::TEMP_COMPLETE,
            'url' => config('app.url').'/user/task/show/'.$data['task_id'],
            'data' => [
                'first'    => $data['first'],
                'keyword1' => $data['address'],            
                'keyword2' => $data['cate_name'],
                'keyword3' => $data['worker_name'],
                'keyword4' => date('Y-m-d H:i'),
                
                'remark' => $data['remark'],                
            ],
        ]);
    }

    /**
     * 收费通知模板
     */
     public static function tempPrice($data)
    {
        $url = '';
        if(array_key_exists('task_id', $data)) {
            $url = config('app.url').'/user/task/show/'.$data['task_id'];
        } else 
        {
            $url = config('app.url').'/user/task/price-detail/'.$data['id'];
        }
        $app = app('wechat.official_account');
        $app->template_message->send([
            'touser' => $data['openid'],
            'template_id' => self::TEMP_PRICE,
            'url' => $url,
            'data' => [
               'first'    => $data['first'],
                'keyword1' => $data['customer_name'],
                'keyword2' => $data['mobile'],            
                'keyword3' => $data['money'],                
                'remark' => $data['remark'],                  
            ],
        ]);
    }


    /**
     * 退单通知模板
     */
    public static function tempRefund($data)
    {
        $app = app('wechat.official_account');
        $app->template_message->send([
            'touser' => $data['openid'],
            'template_id' => self::TEMP_REFUND,
            'url' => config('app.url').'/user/task/show/'.$data['task_id'],
            'data' => [
                'first'    => '退单通知',
                'keyword1' => $data['task_code'],
                //'keyword2' => $data['refund_reason'],
                'keyword2' => date('Y-m-d H:i:s'),
                'remark' => '继续操作请点击',                
            ],
        ]);
    }

    

}
?>